package router4admin

import (
	"Gin-Gorm-boke/boke_admin/yewu/controller4admin"
	"Gin-Gorm-boke/boke_common/middlewares"

	"github.com/gin-gonic/gin"
)

func Router() *gin.Engine {
	r := gin.Default()
	r.Use(middlewares.CorsMiddleWare())

	r.POST("/user/login", controller4admin.Login)
	r.POST("/user/logout", middlewares.AuthUserCheck(), controller4admin.Logout)
	r.GET("/getInfo", middlewares.AuthUserCheck(), controller4admin.GetInfo)
	r.POST("/upload", controller4admin.UploadImg)
	r.GET("/getRouters", middlewares.AuthUserCheck(), controller4admin.GetRouters)
	content := r.Group("/content")
	{
		tag := content.Group("/tag")
		{
			tag.GET("/list", controller4admin.GetTagList)
			tag.POST("", controller4admin.SaveTag)
			tag.DELETE("/:id", controller4admin.DelTag)
			tag.PUT("", controller4admin.UpdateTag)
			tag.GET("/:id", controller4admin.GetTagById)
			tag.GET("/listAllTag", controller4admin.ListAllTag)
		}
		category := content.Group("/category")
		{
			category.GET("/listAllCategory", controller4admin.GetCategoryList)
			category.GET("/list", controller4admin.CategoryPageList)
			category.POST("", controller4admin.SaveCategory)
			category.DELETE("/:id", controller4admin.DelCategory)
			category.PUT("", controller4admin.UpdateCategory)
			category.GET("/:id", controller4admin.GetCategoryById)
		}
		article := content.Group("/article")
		{
			article.POST("", controller4admin.SaveArticle)
			article.GET("/list", controller4admin.GetArticleList)
			article.GET("/:id", controller4admin.GetArticleById)
			article.PUT("", controller4admin.UpdateArticle)
			article.DELETE("/:id", controller4admin.DelArticleById)
		}
		menu := content.Group("/menu")
		{
			menu.GET("/list", controller4admin.GetMenuList)
		}
		link := content.Group("/link")
		{
			link.GET("/list", controller4admin.LinkPageList)
			link.POST("", controller4admin.SaveLink)
			link.DELETE("/:id", controller4admin.DelLinkById)
			link.PUT("", controller4admin.UpdateLink)
			link.GET("/:id", controller4admin.GetLinkById)
		}
	}
	system := r.Group("/system")
	{
		role := system.Group("/role")
		{
			role.GET("/list", controller4admin.GetRoleList)
			role.POST("", controller4admin.SaveRole)
			role.PUT("", controller4admin.UpdateRole)
			role.GET("/listAllRole", controller4admin.ListAllRole)
		}
		menu := system.Group("/menu")
		{
			menu.GET("/treeselect", controller4admin.GetMenuTree)
			menu.GET("/list", controller4admin.GetMenuList)
			menu.GET("/roleMenuTreeselect/:id", controller4admin.GetMenuTreeById)
		}
		user := system.Group("/user")
		{
			user.GET("/list", controller4admin.GetUserList)
			user.POST("", controller4admin.SaveUser)
			user.GET("/:id", controller4admin.GetUserById)
			user.PUT("", controller4admin.UpdateUser)
			user.DELETE("/:id", middlewares.AuthUserCheck(), controller4admin.DelUser)
			user.PUT("/changeStatus", controller4admin.ChangeStatus)
		}
	}

	return r
}
